﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BitcoinMarket.Data
{
    public class DataMarketOpen
    {
        public const string TABLE_NAME = "MARKETOPEN";
        public const string COLUMN_ORDER_ID = "ORDERID";
        public const string COLUMN_ORDER_TYPE = "ORDERTYPE";
        public const string COLUMN_BTC_PRICE = "BTCPRICE";
        public const string COLUMN_BTC_VOLUME = "BTCVOLUME";

        public DataTable OrderTable;
        public DateTime OrderTime;

        public DataMarketOpen()
        {
            Initialized();
        }

        private void Initialized()
        {
            //자료 시간 설정
            OrderTime = new DateTime(2015, 1, 1);

            //데이터 테이블 초기화
            DataColumn col;

            OrderTable = new DataTable(TABLE_NAME);
            
            col = OrderTable.Columns.Add();
            col.ColumnName = COLUMN_BTC_PRICE;
            col.DataType = System.Type.GetType("System.Decimal");

            col = OrderTable.Columns.Add();
            col.ColumnName = COLUMN_BTC_VOLUME;
            col.DataType = System.Type.GetType("System.Decimal");

        }

        public void AddRow(double dbBTCPrice, double dbBTCVolume)
        {
            try
            {
                DataRow dr = OrderTable.NewRow();
                dr[COLUMN_BTC_PRICE] = dbBTCPrice;
                dr[COLUMN_BTC_VOLUME] = dbBTCVolume;
                OrderTable.Rows.Add(dr);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

        public void Clear()
        {
            OrderTable.Clear();
        }

        public int RowCount()
        {
            return OrderTable.Rows.Count;
        }

    }
}
